"""
测试配置文件
"""
import pytest
import asyncio
from fastapi.testclient import TestClient
from tortoise.contrib.test import finalizer, initializer
from app.main import app


@pytest.fixture(scope="session")
def event_loop():
    """创建事件循环"""
    loop = asyncio.get_event_loop()
    yield loop


@pytest.fixture(scope="session", autouse=True)
async def initialize_tests():
    """初始化测试数据库"""
    await initializer(["app.models.user"])
    yield
    await finalizer()


@pytest.fixture
def client():
    """创建测试客户端"""
    with TestClient(app) as c:
        yield c